/**
 * Created with IntelliJ IDEA
 * Description:
 * User: SEKI TOMOKI
 * Date: 2023-09-06
 * Time: 20:20
 */
class Solution {
    public int countSegments(String s) {
        int ret = 0;//记录字符串中单词的个数
        char[] array = s.toCharArray();//把字符串拆成数组
        boolean flg = false;
        for(int i = 0; i < array.length; i++) {
            if(array[i] == ' ') {
                flg = false;
                continue;
            }else if(flg == false){//走到这里说明遇到了一个单词的首字母，计数器 +1
                flg = true;
                ret += 1;
            }else {//走到这里说明遇到了一个单词的非首字母
                flg = true;
            }
        }
        return ret;
    }
}